package com.zhangyu.shadow.repair.delegate.history;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.view.View;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zhangyu.shadow.repair.R;
import com.zhangyu.shadow.repair.delegate.bean.VehicleBean;

import java.util.List;

/**
 * @author zhangyu
 * @date 2018/12/4
 */

public class HistoryAdapter extends BaseQuickAdapter<VehicleBean, BaseViewHolder> {
    private VectorDrawableCompat mDrawableCompatComplete;
    private VectorDrawableCompat mDrawableChevron;

    public HistoryAdapter(Context context, int layoutResId, @Nullable List<VehicleBean> data) {
        super(layoutResId, data);
        mDrawableCompatComplete = VectorDrawableCompat.create(context.getResources(),
                R.drawable.vector_drawable_bus_complete, context.getTheme());
        mDrawableChevron = VectorDrawableCompat.create(context.getResources(),
                R.drawable.ic_chevron_right_gray_24dp, context.getTheme());
    }

    @Override
    protected void convert(BaseViewHolder helper, VehicleBean item) {
        helper.setImageDrawable(R.id.img_bus, mDrawableCompatComplete);
        helper.setText(R.id.tv_bus_number, item.getVehicleCode());
        helper.setText(R.id.tv_maintain_type, item.getTypeName());
        helper.setText(R.id.tv_bus_line, item.getRouteName());
        helper.setText(R.id.tv_bus_in_fac_time, "进厂时间:" + item.getInFactoryTime());
        helper.setText(R.id.tv_bus_doing_time, "开工时间:" + item.getActualStartTime());
        helper.setText(R.id.tv_bus_out_done_time, "完工时间:" + item.getActualEndTime());
        helper.setText(R.id.tv_bus_out_fac_time, "出厂时间:" + item.getOutFactoryTime());
        //报修内容
        TextView tvReportContent = helper.getView(R.id.tv_report_content);
        if (item.getReportContent() == null || item.getReportContent().isEmpty()) {
            tvReportContent.setVisibility(View.GONE);
        } else {
            tvReportContent.setVisibility(View.VISIBLE);
            tvReportContent.setText(String.format("报修内容:%s", item.getReportContent()));
        }
        //维修内容
        TextView tvRepairContent = helper.getView(R.id.tv_repair_content);
        if (item.getWorkContent() == null || item.getWorkContent().isEmpty()) {
            tvRepairContent.setVisibility(View.GONE);
        } else {
            tvRepairContent.setVisibility(View.VISIBLE);
            tvRepairContent.setText(String.format("维修内容:\n%s", item.getWorkContent()
                    .replace(",","\n")));
        }
        helper.setImageDrawable(R.id.iv_chevron, mDrawableChevron);
    }
}
